<template>
	<view>
		<view class="cu-custom bg-white" style="height: 490rpx;" >
			<view class="cu-bar fixed" style="padding-right: 0rpx;background-image: url('https://ewm.rsj.jinhua.gov.cn/jhrs/api/common/file/show/jycy/152a86726a3d45b4a009a739e70c2fac');background-size: 100% 100%;" >
				<view class="box" >
					<view class="box-hd " >		
					<view style="margin-top: 100rpx;padding-left: 30rpx;display: flex;align-items: center;justify-content: center;">
						<image style="width: 100rpx;height: 100rpx;" class="round" :src="photoPath?photoPath:(sex=='2'?'/static/user/avatar_gril.png':'/static/user/avatar_boy.png')">
						<view  style="color: #888;"><text style="padding-left: 20rpx;font-size: 32rpx;" class="text-white">{{fullName}}</text><text style="padding-left: 10rpx; font-size: 32rpx;" class="text-yellow">欢迎您</text></view>
					</view>		
					</view>
						<view class="box-bd bg-white">
							
							<view v-if="showScan" class="item">
								<view>
									<view style="width: 120rpx;height: 120rpx;">
										<image src="/static/iconfont/scan.png" style="width: 120rpx;height: 120rpx;" @click="getScancode"></image>
									</view>
									<view class=" text-center" style="color: #444444;margin-top: -10rpx;">扫一扫</view>
								</view>
							</view>
							<view class="item">
								<view>
									<view style="width: 120rpx;height: 120rpx;">
										<image src="/static/iconfont/qrcode.png" style="width: 120rpx;height: 120rpx;" @click="gotoPersonCode"></image>
									</view>
									<view class=" text-center" style="color: #444444;margin-top: -10rpx;">就业码</view>
								</view>
							</view>
							<view class="item">
								<view>
									<view style="width: 120rpx;height: 120rpx;">
										<image src="/static/iconfont/settings.png" style="width: 120rpx;height: 120rpx;" @click="gotoSetting"></image>
									</view>
									<view class=" text-center" style="color: #444444;margin-top: -10rpx;">设置</view>
								</view>
							</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="myList&&myList.length>0"  class="cu-list menu sm-border margin-top-sm bg-white"  >
			<view class="cu-item arrow" v-for="(item,index) in myList" :key="index" @tap="menuTap(item)">
				<view class="content">
					<text :class="item.color.substring(0, 1)!='#'?[item.icon,'text-' + item.color]:[item.icon]" :style="[{color:item.color.substring(0, 1)=='#'? item.color:''}]"></text>
					<text >{{item.title}}</text>
				</view>
			</view>
		</view>
		<view class="cu-list menu sm-border bg-white"  >
			<!--<view class="cu-item arrow" >
				<view class="content"  @tap="menuTap({ linkType:'router',linkName:'help',linkPath:'/pages/system/help/help'})">
					<text class="iconfont icon-bzzx text-blue"></text>
					<text >帮助中心</text>
				</view>
			</view>-->
			<view class="cu-item arrow" >
				<view class="content" @tap="menuTap({ linkType:'router',linkName:'about',linkPath:'/pages/system/about/about'})">
					<text class="iconfont icon-gywm text-blue"></text>
					<text >关于我们</text>
				</view>
			</view>
			<view class="cu-item arrow" >
				<view class="content" @tap="menuTap({ linkType:'router',linkName:'feedback',linkPath:'/pages/system/feedback/feedback'})">
					<text class="iconfont icon-yjfk text-blue"></text>
					<text >意见反馈</text>
				</view>
			</view>
		</view>
		<u-modal v-model="modelShow"  :content="modelContent" :confirm-color="userType=='20'?'#0081ff':'#f37b1d'"></u-modal>
		
	</view>
</template>

<script>
	import store from "@/store"
	import api from '@/api/society/my/my.js'
	import systemConfig from '@/common/config/systemConfig.js'
	export default {
		onShow() {
			let showScan=false
			// #ifdef H5
			let browerInfo = store.state.hh_browerInfo
			if(!browerInfo){
				browerInfo=util.getBrowerInfo()
			}
			if(browerInfo){
				this.browerInfo=browerInfo
				let type=browerInfo.browserType
				if(type=='zlb'||type=='zlb-alipay'||type == 'alipay'){
					showScan=true
					this.zlbFlag = true
					ZWJSBridge.setTitle({ title: '我的'}) .then((result) => { console.log(result) }).catch((error) => { console.log(error) })
				}else{
					this.zlbFlag = false
				}
			}else{
				this.zlbFlag = false
			}
			//#endif
			// #ifndef H5
				showScan=true
				this.zlbFlag = false
			//#endif
			this.showScan=showScan
		},
		data() {
			return {
				userType:store.state.hh_userType,
				fullName: store.state.hh_user.fullName,
				sex: store.state.hh_user.sex,
				photoPath: store.state.hh_user.photoPath,
				myList:[],
				clientId:store.state.hh_clientId,
				areaCode:store.state.hh_areaCode,
				modelShow:false,
				modelContent:'功能目前在测试中，尚未开放',
				StatusBar: '',
				CustomBar: '',
				bgImage:'https://ewm.rsj.jinhua.gov.cn/jhrs/api/common/file/show/jycy/152a86726a3d45b4a009a739e70c2fac',
				bgColor:'',
				showScan:false,
				zlbFlag:false
				
			}
		},
		onReady() {
			this.StatusBar= this.$StatusBar;
			this.CustomBar= this.$CustomBar;
			console.log(this.StatusBar)
			this.queryMenu()
			
		},
		computed: {
			style() {
				var StatusBar= this.StatusBar||0;
				var CustomBar= this.CustomBar||50;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar+400}rpx;padding-top:${StatusBar}rpx;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		methods: {
			queryMenu(){
				const menuDate={}
				if(this.userType=='30'){
					menuDate.menuPro = 'company'
				} else if(this.userType=='20'){
					menuDate.menuPro = 'person'
				} else{
					menuDate.menuPro = 'manager'
				}
				menuDate.areaCode = this.areaCode
				menuDate.clientId=this.clientId
				setTimeout(() => {
					const myData = Object.assign({},menuDate)
					myData.menuType = 'my'
					this.$http.post(api.getMenuList, myData).then(res => {
						this.myList=res.result
					}).catch(error => {
						
					})
				}, 50);
			},
			menuTap(item){
				// 点击菜单
				if(item.linkType){
					if(item.linkType=='router'){
						if(item.linkName){
							let flag = false
							for(var num in ROUTES){
								const router = ROUTES[num]
								if(item.linkName == router.name){
									flag = true
									break
								}
							}
							if(flag){
								let params={}
								if(item.param1){//自定义参数1为请求参数，不为空时传入
									try{
										params = JSON.parse(item.param1)
									}catch(e){
										this.modelContent='请求参数（param1）配置必须是json格式'
										this.modelShow = true
										return
									}
								}
								params.headerTitle=item.title//标题
								params.menuId=item.menuId//菜单id
								params.serviceCode=item.param2//服务事项编码
								params.serviceName=item.param3//服务事项名称
								this.$Router.push({ path:item.linkPath,query:params})
							}else{
								this.modelContent='功能配置异常，未找到跳转页面'
								this.modelShow = true
							}
							
						}else{
							this.modelContent='功能目前在测试中，尚未开放'
							this.modelShow = true
						}
					}else if(item.linkType=='h5'){
						if(item.linkUrl){
							this.gotoOhterPage(item)
						}else{
							this.modelContent='功能目前在测试中，尚未开放'
							this.modelShow = true
						}
					}else{
						this.modelContent='功能目前在测试中，尚未开放'
						this.modelShow = true
					}
					
				}else{
					this.modelContent='功能目前在测试中，尚未开放'
					this.modelShow = true
				}
				
			},
			getScancode: function () {
				// #ifndef H5
			    uni.scanCode({
			        success: function (res) {
			            console.log('条码类型：' + res.scanType);
			            console.log('条码内容：' + res.result);
						const result = res.result
						// 判断是否url 如果是url 则直接跳转
						if (this.$validate.isUrl(result)) {
							const item={}
							item.linkUrl=result
					        item.title="扫码结果";
							this.gotoOhterPage(item)
						}
						// 调用后端判断是否平台生成的二维码
						
			        }
			    });
				//#endif
				// #ifdef H5
				    if(this.zlbFlag){
						let vim=this
						ZWJSBridge.scan({ type: "qrCode" }).then((data) => {
							let result = data.text
							// 判断是否url 如果是url 则直接跳转
					        if (vim.$validate.isUrl(result)) {
					        	const item={}
					        	item.linkUrl=result
					        	item.title="扫码结果";
					        	vim.gotoOhterPage(item)
					        }else{
								uni.showToast({
								  icon: 'none',
								  title: "扫码结果:"+result,
								  duration:8000
								})
							}
						 }).catch((error) => { console.log(error); });
					}
					
				//#endif
			},
			gotoOhterPage(item){
				const url =item.linkUrl
				if(url){
					let params={}
					params.headerTitle=item.title//标题
					params.menuId=item.menuId//菜单id
					params.serviceCode=item.param2//服务事项编码
					params.serviceName=item.param3//服务事项名称
					
					params.url=encodeURIComponent(url)
					if(item.linkPath){
						this.$Router.push({ path: item.linkPath, query: params });
					}else{
						this.$Router.push({ path: '/pages/system/web-view/webViewLogin', query: params });
					}
				}else{
					this.modelContent='没有传入跳转的链接'
					this.modelShow = true
				}
			},
			gotoPersonCode(){
				if(store.state.hh_user.realFlag){
					this.$Router.push({ name:'workCode'})
				}else{
					this.$Router.push({ name:'addCard'})
				}
			},
			gotoSetting(){
				this.$Router.push({ name:'setting'})
			}
		}
	}
</script>

<style lang="scss">
.box{
	width: 100%;
	border-radius: 20rpx;
	margin: 0 auto;
	.box-hd{
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
		width: 100%;
		height: 294rpx;
		.avator{
			width: 160rpx;
			height: 160rpx;
			background: #fff;
			border: 5rpx solid #fff;
			border-radius: 50%;
			overflow: hidden;
			img{
				width: 100%;
				height: 100%;
			}
		}
		.phone-number{
			width: 100%;
			text-align: center;
		}
	}
	.box-bd{
		display: flex;
		flex-wrap: nowrap;
		flex-direction: row;
		justify-content: center;
		width: 100%;
		.item{
			flex: 1 1 auto;
			display: flex;
			flex-wrap: wrap;
			flex-direction: row;
			justify-content: center;
			margin: 15rpx 0;
			.text{
				width: 100%;
				text-align: center;
			}
		}
	}
}

</style>
